package com.longdaji.decoration.ui.creditassess;

import android.text.TextUtils;
import android.util.Log;

import com.longdaji.decoration.base.RxPresenter;
import com.longdaji.decoration.data.DataManager;
import com.longdaji.decoration.data.network.CommonSubscriber;
import com.longdaji.decoration.data.network.HttpResponse;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by longtao on 2017/12/19.
 */

public class CreditAssessPresenter extends RxPresenter<CreditAssessContract.View> implements CreditAssessContract.Presenter {
    private final static String TAG = CreditAssessPresenter.class.getSimpleName();
    private DataManager mDataManager;

    @Inject
    public CreditAssessPresenter(DataManager dataManager) {
        this.mDataManager = dataManager;
    }


    @Override
    public void verifyCreditScore(String certNo, String name) {
        addSubscribe(mDataManager.verifyCreditScore(certNo, name)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new CommonSubscriber<HttpResponse>() {
                    @Override
                    public void onSuccess(HttpResponse httpResponse) {
                        Log.d(TAG, "HttpResponse is" + httpResponse);
                        if (mView == null) {
                            return;
                        }
                        if (TextUtils.equals("0", httpResponse.getStatusCode())) {
                            mView.showVerifySuccess();
                        } else {
                            mView.showVerifyFail();
                        }

                    }

                    @Override
                    public void onFailed(String msg) {
                        Log.d(TAG, "msg is " + msg);
                        if (mView != null) {
                            mView.showVerifyFail();
                        }
                    }
                }));
    }
}
